<?php include $this->admin_tpl('meta', 'admin');?>
<title>添加/编辑员工信息</title>
</head>
<body>
<article class="page-container">
<div class="formdoby_normal">
	<form method="post" onsubmit="return dosub(this)">
		<ul>
			 <li>
				<label><span class="c-red">*</span>姓名：</label>
			 	<input type="text" class="input" name="name" value="<?php echo $data['name']?>" placeholder="请输入姓名">
				<input name="is_ss" type="checkbox" <?php if($data['is_ss']) echo 'checked';?> value="1"> 购买社保
			</li>
			<li>
				<label><span class="c-red">*</span>部门：</label>
				 <select name="department_id" size="1" onchange="change_department(this)">
					<option value="">请选择部门</option>
					<?php echo $select_menus;?>			
				 </select>
				 <label style="width:50px;margin-left:15px;"><span class="c-red">*</span>职位：</label>
				 <select  name="position_id" id="position" size="1">
					<?php if(isset($position_list)){
					foreach($position_list as $v){?>
					<option value="<?php echo $v['id']?>" <?php if($data['position_id']==$v['id']){ echo 'selected';}?>><?php echo $v['name']?></option>
					<?php }}else{?>
					<option value="">请先选择部门</option>
					<?php }?>
				 </select>
			 </li>
			 <li>
				<label><span class="c-red">*</span>电话：</label>
			 	<input type="text" class="input" name="mobile" value="<?php echo $data['mobile']?>" placeholder="请输入电话">
			 </li>
			 <?php if($data['money_id']){?><li class="c-red">薪资修改请到薪资管理列表操作</li><?php }?>
			 <li>
				<label><span class="c-red">*</span>薪资：</label>
			 	<input type="text" class="input" name="money" <?php if($data['money_id']) echo 'disabled'?> value="<?php echo $data['money']?>" placeholder="请输入薪资"> 元/月 <input name="is_second" type="checkbox" <?php if($data['money_id']) echo 'disabled'?> <?php if($data['is_second']) echo 'checked';?> value="1"> 双轨制
			 </li>
			 <li id="remark" <?php if(!$data['is_second']) echo 'style="display:none"';?>>
				<label><span class="c-red">*</span>双轨制工资备注：</label>
			 	<input style="width:455px;" <?php if($data['money_id']) echo 'disabled'?> type="text" class="input" name="remark" value="<?php echo $data['remark']?>" placeholder="请输入双轨制工资备注">
			 </li>
			 <li>
				<label><span class="c-red"></span>餐补：</label>
			 	<input type="text" class="input" name="meal_money" <?php if($data['money_id']) echo 'disabled'?> value="<?php echo $data['meal_money']?>" placeholder="请输入餐补金额"> 元/月
			 </li>
			 <li>
				<label><span class="c-red"></span>房补：</label>
			 	<input type="text" class="input" name="housing_money" <?php if($data['money_id']) echo 'disabled'?> value="<?php echo $data['housing_money']?>" placeholder="请输入房补金额"> 元/月
			 </li>
			 <li>
				<label><span class="c-red"></span>身份证号：</label>
			 	<input type="text" class="input" name="card_id" value="<?php echo $data['card_id']?>" placeholder="请输入身份证号">
			 </li>
			 <li>
				<label><span class="c-red"></span>地址：</label>
			 	<input type="text" class="input" style="width:80%;" name="address" value="<?php echo $data['address']?>" placeholder="请输入地址">
			 </li>			 
			 
			 <li>
				<label><span class="c-red"></span>银行名称：</label>
			 	<input type="text" class="input" name="bank_name" value="<?php echo $data['bank_name']?>" placeholder="请输入银行名称">
			 </li>
			 <li>
				<label><span class="c-red"></span>银行卡号：</label>
			 	<input type="text" class="input" name="bank_code" value="<?php echo $data['bank_code']?>" placeholder="请输入银行卡号">
			 </li>
			 <li>
				<label><span class="c-red"></span>银行户名：</label>
			 	<input type="text" class="input" name="bank_account" <?php if($data['bank_account']==$data['name']||!$_GET['id']) echo 'disabled';?> value="<?php echo $data['bank_account']?>" placeholder="请输入银行账户名">
				<input name="is_same" type="checkbox" <?php if($data['bank_account']==$data['name']||!$_GET['id']) echo 'checked';?> value="1"> 与员工姓名一致
			 </li>
			 <li>
				<label>入职时间：</label>
				<input type="text" class="input-text laydate-icon" style="width:175px;height:30px;margin-left:5px" name="in_time" id="in_time" value="<?php echo $data['in_time'] ? date('Y-m-d',$data['in_time']):date('Y-m-d');?>"></span>
			 <span class="span_input">
			 	<label class="label_radio"><input name="status" type="radio" value="1" <?php echo  $data['status']==1 ? 'checked' : '';?>> 在职</label>
			 	<label class="label_radio"><input name="status" type="radio" value="0" <?php echo  $data['status']==0 ? 'checked' : '';?>> 离职</label>
			 </span>
				<label style="width:80px;margin-left:20px;">离职时间：</label>
				<input type="text" class="input-text laydate-icon" style="width:175px;height:30px;margin-left:5px" name="out_time" id="out_time" value="<?php echo $data['out_time']?date('Y-m-d',$data['out_time']):''; ?>"></span>
			 </li>
			 <li>
				<label><span class="c-red">*</span>紧急联系人：</label>
			 	<input type="text" style="width:165px;" class="input" name="re_name" value="<?php echo $data['re_name']?>" placeholder="请输入紧急联系人姓名">
				<label style="width:85px;margin-left:20px;">联系人电话：</label>
			 	<input type="text" style="width:160px;" class="input" name="re_mobile" value="<?php echo $data['re_mobile']?>" placeholder="请输入紧急联系人电话">
			 </li>
			 <li>
				<label><span class="c-red"></span>学历：</label>
				 <select  name="education" size="1" style="width:180px;">
					<option value="">请选择学历</option>
					<option value="未知" <?php if($data['education'] == '未知'){echo 'selected';}?>>未知</option>
					<option value="初中"  <?php if($data['education'] == '初中'){echo 'selected';}?>>初中</option>
					<option value="高中/中专"  <?php if($data['education'] == '高中/中专'){echo 'selected';}?>>高中/中专</option>
					<option value="大专"  <?php if($data['education'] == '大专'){echo 'selected';}?>>大专</option>
					<option value="本科"  <?php if($data['education'] == '本科'){echo 'selected';}?>>本科</option>
					<option value="研究生"  <?php if($data['education'] == '研究生'){echo 'selected';}?>>研究生</option>
				 </select>
				<label style="width:85px;margin-left:20px;"><span class="c-red"></span>专业：</label>
				<input type="text" style="width:160px;" class="input" name="major" value="<?php echo $data['major']?>" placeholder="请输入专业">
			 </li>
			 <li>
				<label><span class="c-red"></span>籍贯：</label>
				<input type="text" style="width:165px;" class="input" name="native_place" value="<?php echo $data['native_place']?>" placeholder="请输入籍贯">
				<label style="width:85px;margin-left:20px;"><span class="c-red"></span>合同编号：</label>
				<input type="text" style="width:160px;" class="input" name="agree_no" value="<?php echo $data['agree_no']?>" placeholder="请输入籍贯">
			 </li> 

			 <li class="text-c">
			 	<input type="hidden" name="dosubmit" value="1">
				<input type="hidden" name="id" value="<?php echo $data['id'];?>">
				<input type="hidden" name="money_id" value="<?php echo $data['money_id'];?>">
			 	<input class="dosubmit w_120 btn-primary radius" type="submit" value="提交">
			 	<input class="btn w_120 btn-default radius" type="button" value="取消" onclick="yzmcms_close()">
			 </li>
		</ul>
	</form>
</div>
</article>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/laydate/1.1/laydate.js"></script>
<script type="text/javascript">
	$("input[name='is_same']").click(function(){
		var obj = $('input[name="bank_account"]');
		if($(this).is(':checked')){
			obj.val($('input[name="name"]').val());
			obj.attr('disabled','disabled');
		}else{
			obj.removeAttr('disabled');
		}
	})
	
	$("input[name='is_second']").click(function(){
		if($(this).is(':checked')){
			$('#remark').show();
		}else{
			$('#remark').hide();
		}
	})
	
	function change_department(obj){
		var department_id = $(obj).val();
		$.ajax({
			type: 'get',
			url: '<?php echo U('get_position');?>', 
			data: {department_id:department_id},
			dataType: "json", 
			success: function (res) {
				if(res['status']==1){
					$('#position').html('');
					var html = '';
					$.each(res['data'],function(i,val){
						html += '<option value="'+val['id']+'">'+val['name']+'</option>';
					});
					$('#position').html(html);
				}
			}
		})
	}
	
	function dosub(obj){
		 if(obj.name.value==''){
			 layer.msg('姓名不能为空！', {icon:2});
			 return false;
		 }
		 if(obj.department_id.value==''){
			 layer.msg('请选择部门！', {icon:2});
			 return false;
		 }
		 if(obj.position_id.value==''){
			 layer.msg('请选择岗位！', {icon:2});
			 return false;
		 }
		 <?php if(!$data['id']){?>
		 if(obj.money.value==''){
			 layer.msg('请输入薪资！', {icon:2});
			 return false;
		 }
		 <?php } ?>
		 if(obj.re_name.value==''){
			 layer.msg('请输入紧急联系人！', {icon:2});
			 return false;
		 }
		 if(obj.card_id.value==''){
			 layer.msg('身份证号不能为空！', {icon:2});
			 return false;
		 }
		 if(obj.re_mobile.value==''){
			 layer.msg('请输入紧急联系人电话！', {icon:2});
			 return false;
		 }
		 if(obj.status.value==0&&obj.out_time.value == ''){
			 layer.msg('请选择离职时间！', {icon:2});
			 return false;
		 }
		 if($("input[name='is_second']").is(':checked')&&obj.remark==''){
			layer.msg('请输入双轨制工资备注', {icon:2});
			return false;
		 }
		 if(obj.in_time.value==''){
			 layer.msg('请选择入职时间！', {icon:2});
			 return false;
		 }
		 if(obj.money.value!='' && isNaN(obj.money.value)){
			 layer.msg('薪资只能为数字类型！', {icon:2});
			 return false;
		 }
		 if(obj.meal_money.value!='' && isNaN(obj.meal_money.value)){
			 layer.msg('餐补只能为数字类型！', {icon:2});
			 return false;
		 }
		 if(obj.housing_money.value!='' && isNaN(obj.housing_money.value)){
			 layer.msg('房补只能为数字类型！', {icon:2});
			 return false;
		 }
        $.ajax({
            type: 'POST',
            url: '<?php echo U('member_add');?>', 
            data: $(obj).serialize(),
		    dataType: "json", 
            success: function (msg) {
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1, time:800}, function(){
						parent.location.reload();
					});
			    }else{
					layer.msg(msg.message, {icon:2});
				}
            }
        })		 
		return false;			 
	}
	var in_time = {elem:'#in_time',format:'YYYY-MM-DD',min:'1999-01-01',max:'2099-01-01',istime:true,istoday:false,choose:function(datas){}
	};
	var out_time = {elem:'#out_time',format:'YYYY-MM-DD',min:'1999-01-01',max:'2099-01-01',istime:true,istoday:false,choose:function(datas){}};
	laydate(in_time);
	laydate(out_time);
</script> 

</body>
</html>